<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<c:set var="ctx" value="${pageContext.request.contextPath}" /> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script src="${ctx}/resources/js/jquery-1.11.1.js"></script>

<script type="text/javascript">
		function displayUser(id){
			window.location.href = '${ctx}/users/'+id;
		}
		
		function modify(id){
			window.location.href = '${ctx}/users/'+id+'/profile';
		}

		function deleteConfirm(id) {
	        if (confirm("确认要删除？")) {
	        	$.ajax({ 
	                type:'delete',     
	                url:'${ctx}/users/'+id, 
	                dataType:'json', 
	                success:function(data){
	                	alert(data.success);
	                	window.location.reload();//刷新当前页
	                	//refresh();
	                },
	                error:function(){
	                	alert("error");
	                }
	            }); 
	        }
	    }
</script>
<title>Users</title>
</head>
<body>

	<table>
		<tr>
			<td>序号</td>
			<td>id</td>
			<td>用户名</td>
			<td>密码</td>
		</tr>
		<c:forEach var="user" items="${userList}" varStatus="status">
			<tr>
				<td>${status.index}</td>
				<td>${user.userid}</td>
				<td>${user.username}</td>
				<td>${user.password}</td>
				<td>
					<input type="button" value="删除" onClick="deleteConfirm(${user.userid})"> 
					<input type="button" value="查看" onClick="displayUser(${user.userid})">
					<input type="button" value="修改" onClick="modify(${user.userid})">
					<form:form method="delete" action="${ctx}/users/${user.userid}">
						<p class="submit"><input type="submit" value="使用spring mvc表单标签Delete Pet"/></p>
					</form:form>
				</td>
			</tr>	
		</c:forEach>
	</table>
	<div>新增用户</div>
	<form action="<%=request.getContextPath()%>/users" name="form" method="POST">
		<div><span>用户名:</span><input type="text" id="userName" name="username"></div>
		<div><span>密码:</span><input type="password" id="password" name="password"></div>
		<div><input type="submit" value="新增"></div>
	</form>

	
</body>
</html>